# -*- coding: utf-8 -*-
from datetime import datetime
from typing import Optional

from pydantic import Field, ConfigDict

from App.app.admin.schemas.menu_schema import GetMenuListDetails
from App.common.schema import SchemaBase
from App.utils.enums import StatusType


class SysRoleSchema(SchemaBase):
    model_config = ConfigDict(
        from_attributes=True
    )

    name: str
    status: StatusType = Field(default=StatusType.enable)
    remark: Optional[str] = ""
    created_time: datetime
    updated_time: datetime | None = None


class CreateSysRoleParam(SchemaBase):
    name: str
    status: StatusType = Field(default=StatusType.enable)
    remark: Optional[str] = None


class UpdateSysRoleParam(SchemaBase):
    id: int
    name: Optional[str] = None
    status: Optional[StatusType] = None
    remark: Optional[str] = None


class GetSysRoleListDetails(SysRoleSchema):
    # 合并父类配置
    model_config = ConfigDict(
        from_attributes=True,
        json_encoders=SchemaBase.model_config.get("json_encoders", {})  # 继承父类编码器
    )
    id: int
    created_time: datetime
    updated_time: datetime | None = None
    menus: list[GetMenuListDetails]


class UpdateRoleMenuParam(SchemaBase):
    id: int
    menus: list[int]
